/**
 * @Author：ming
 * @Date：2023/10/6 2:03 AM
 * @Filename：Lc435
 */

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author ming
 */
public class Lc435 {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1]-o2[1];
            }
        });
        int end = 0;
        int count = 0;
        for (int i = 0; i < intervals.length; i++) {
            if(i ==0){
                end = intervals[0][1];
            }else {
                if(intervals[i][1]>end){
                    end = intervals[i][1];
                }else {
                    count++;
                }
            }
        }
        return  count;
    }
}
